<?

if ($c = stack('name')) {
	
	$_id_component	= $DATA['components'][$c]['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value
	$_tags			= component_tags($c);
	
//debug($_tags);
	
	$_crit = "id_data=$_id_data AND id_parent=$_id_component AND ".dbAndL('attr', AA_VISIBLE);

	$s = array_extend( array('path' => 'album', 'tn' => FP_TN_DIR, 'w' => 800, 'h' => 600, 'tnw' => 128, 'tnh' => 96, 'imode' => MI_FIT, 'tnmode' => MI_FIT, 'gmode' => MI_FIT, 'gw' => 128, 'gh' => 96, 'gtpb' => 0, 'gparam' => 'gallery', 'param' => 'id', 'show_tn' => 1, 'nav' => 0, 'navigator' => 1, 'circular' => 0, 'autoscroll' => 0, 'fancybox' => 0, 'autogallery' => 0,), $DATA['components'][$c]['settings']);

	$s['path'] = FP_UPLOAD_PATH."$s[path]/";

	if ($s['autogallery']) {
		if ($t = datafetch('db_item', tb('data'), $_crit, 'id', 'id_index')) {
			header("Location: "._transformURL($CURRENT->url, array('add_param' => array($s['gparam'] => $t['id']))));
			exit;
		}
	}

	$DATA['components'][$c]['data'] = array_mark_bounds( datafetch_array('db_list', array('table' => tb('data'), 'where' => $_crit, 'order' => 'id_index', 'index' => 'id' )));
	
	

	foreach($DATA['components'][$c]['data'] as $k => $v) {
		$DATA['components'][$c]['data'][$k] = array_merge($v, datafetch_array('loadmeta', $_id_meta, 
			array('parent' => $k, 'assoc' => context('lang'), 'getclob' => 1)));
			
		$DATA['components'][$c]['data'][$k]['image'] = checkImage($s['path'], $k);
	}
//debug($DATA['components'][$c]['data']);

//	$DATA['components'][$c]['data'] = datafetch_array('gallery', FP_UPLOAD_PATH.$DATA['components'][$c]['settings']['path']);	// load existing images list
	
	unstack();
}